package com.cf.studiomanage.controller;

import com.cf.studiomanage.entity.Message;
import com.cf.studiomanage.service.MessageService;
import com.cf.studiomanage.util.R;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/messages")
@Tag(name = "消息通知模块", description = "系统消息发送、查询、标记已读接口")
public class MessageController {

    @Autowired
    private MessageService service;

    @PostMapping("/send")
    @Operation(summary = "发送消息", description = "管理员发送系统/邮件/短信通知")
    public R send(@RequestBody Message message) {
        return service.send(message) ? R.ok("发送成功") : R.error("发送失败");
    }

    @GetMapping("/user/{userId}")
    @Operation(summary = "用户查看消息", description = "查看当前用户收到的所有通知")
    public R getUserMessages(@PathVariable Long userId) {
        return R.ok().data("list", service.getUserMessages(userId));
    }

    @PostMapping("/read/{id}")
    @Operation(summary = "标记为已读", description = "将某条消息标记为已读状态")
    public R markAsRead(@PathVariable Long id) {
        return service.markAsRead(id) ? R.ok("标记成功") : R.error("标记失败");
    }
}
